#ifndef PQUEUE_WIDX_H
#define PQUEUE_WIDX_H

#include <functional>
#include <vector> 

using std::function;
using std::less;
using std::vector;

class PQueueWidx {
public:
    using CmpFunc = function<bool(int a, int b)>;
private:
    vector<int> pqv;
    vector<int> qidxv;
    typedef typename vector<int>::const_iterator PQVit;
    typedef typename vector<int>::const_reverse_iterator PQVrit;
    CmpFunc cmp;
public:
    PQueueWidx(CmpFunc cmp = less<int>{}) : cmp(cmp) {}
    void make_heap(void); 
    void up_fix_heap(int val);
    void down_fix_heap(int val);
    void push(int val);
    void pop(void);
    int top(void) { return pqv[0]; }
    int dequeue(void);
    void pop_back(void) {pqv.pop_back();}
    void push_back(int val);
    void clear(void) {pqv.clear(); }
    bool empty(void) {return pqv.empty(); }
    int size(void) {return pqv.size(); }
    PQVit cbegin(void) { return pqv.cbegin();}
    PQVit cend(void) { return pqv.cend();}
    PQVrit crbegin(void) {return pqv.crbegin(); }
    PQVrit crend(void) { return pqv.crend(); }

};

#endif //PQUEUE_WIDX_H
